package server;

import java.util.Collection;

import server.commonData.User;

import com.core.initialize.Message;

/**
 * 服务器发送信息代理
 * @author King
 *
 */
public class ServerTransportProxy
{
	/**发送消息给客户端**/
	public static final void sendMsg(Message msg,long userId)
	{
		User user = ServerEngin.getInstance().getCache().getUser(userId);
		if(user==null)
			return;
		user.getChannel().write(msg);
	}
	
	/**发送消息给客户端**/
	public static final void sendMsg(Message msg,User user)
	{
		if(user==null)
			return;
		user.getChannel().write(msg);
	}
	
	/**
	 * 发给所有客户端
	 * @param msg
	 */
	public static final void sendToAll(Message msg)
	{
		GameCache cache = ServerEngin.getInstance().getCache();
		for(User user:cache.getUserMap().values())
		{
			user.getChannel().write(msg);
		}
	}
	
	/**发送消息给客户端**/
	public static final void sendMsg(Message msg,long... userIds)
	{
		GameCache cache = ServerEngin.getInstance().getCache();
		for(long userId:userIds)
		{
			User user = cache.getUser(userId);
			if(user==null)
				continue;
			user.getChannel().write(msg);
		}
	}
	
	
	/**发送消息给客户端**/
	public static final void sendMsg(Message msg,Collection<Long> userIds)
	{
		GameCache cache = ServerEngin.getInstance().getCache();
		for(long userId:userIds)
		{
			User user = cache.getUser(userId);
			if(user==null)
				continue;
			user.getChannel().write(msg);
		}
	}
	
	/**发送消息给客户端**/
	public static final void sendMsgByUser(Message msg,Collection<User> users)
	{
		for(User user:users)
		{
			if(user==null)
				continue;
			user.getChannel().write(msg);
		}
	}
	/**发送消息给客户端**/
	public static final void sendMsgByUser(Message msg,User... users)
	{
		for(User user:users)
		{
			if(user==null)
				continue;
			user.getChannel().write(msg);
		}
	}
}
